<template>
	<view class=" page">
		<view class="top">
			<view class="photo">
				<view class="avatar">
					<u-avatar v-if="loading" :src="IMAGE_URL + avatar"></u-avatar>
					<text>{{ info[$t('item.user.username')] }}</text>
				</view>
			</view>
		</view>
		<view class="data" v-for="(item, key, index) in infoList" :key="index">
			<p class="title">
				<text>{{ I18list[key] }}</text>
			</p>
			<u-empty v-if="item.length < 1" :text="$t('没有数据')" mode="data"></u-empty>
			<view class="_layout" v-else>
				<view v-for="(ele, i) in item" :key="i">
					<u-image @click="details(ele, i, key)" width="100%" height="200rpx"
						:src="IMAGE_URL + ele.images[0]"></u-image>
				</view>
			</view>
		</view>
		<!-- 图片预览 -->
		<u-mask :show="mask" @click="mask = false">
			<view>
				<u-image width="100%" height="100vh" mode="aspectFit" :src="IMAGE_URL + url"></u-image>
			</view>
		</u-mask>
	</view>
</template>

<script>
	import {
		IMAGE_URL
	} from '../../../config/app'
	export default {
		data() {
			return {
				IMAGE_URL,
				list: [],
				I18list: {
					goods: this.$t('货物'),
					transport: this.$t('运输'),
					exposure: this.$t('曝光台'),
					crossborder: this.$t('跨境货代'),
					professional: this.$t('专业代办'),
					lifead: this.$t('生活广告'),
				},
				info: {},
				id: 0,
				show: false,
				videoContext: null, //视频实例,
				mask: false,
				url: '',
				avatar: '',
				loading: false,
				type: 1,
				infoList: {},
			}
		},
		onLoad(option) {
			this.id = option.id
			this.type = option.type
			this.api()
		},
		onReady() {},
		methods: {
			// 订单详情
			details(data, index, key) {
				this.$u.route({
					url: 'pages/index/detail/detail',
					params: {
						id: data.id,
						type: this.current + 1,
						releaseType: key
					}
				})
			},
			api() {
				this.$u.api.user.getUserHomepage({
					user_id: this.id,
					type: this.type
				}).then(res => {
					console.log(res);
					this.info = res.userInfo
					this.infoList = res.list
					if (this.current == 1) {
						delete this.infoList['lifead']
						delete this.infoList['exposure']
					}
					this.loading = true
				})
			},
			// 点击图片预览
			preview(e) {
				if (e == '') return
				// console.log(this.url);
				this.mask = true
				this.url = e
			},
			videoErrorCallback(e) {
				console.log('视频错误信息:')
				console.log(e.target.errMsg)
			},
			Play(index) {
				this.show = true
				this.videoContext = uni.createVideoContext(`myVideo${index}`);
				this.videoContext.play()
				this.videoContext.requestFullScreen();
			},
			playVedio(index) {

			},
			fullscreenchange(e) {
				// console.log(e);
				if (!e.detail.fullScreen) {
					this.videoContext.pause()
					this.videoContext.seek(0)
					this.show = false
				}
			}

		},
	}
</script>

<style lang="scss" scoped>
	._layout {
		display: grid;
		grid-template-columns: repeat(3, 30%);
		justify-content: space-between;
		grid-gap: 10px;
		padding: 20rpx 0 30rpx 0;
	}
	
	.data {
		// min-height: 300rpx;
		width: 90%;
		margin: 0 auto;
		display: flex;
		flex-direction: column;

		.title {
			font-size: 34rpx;
			color: orange;
			line-height: 70rpx;
			font-weight: bold;
			border-bottom: 4rpx solid orange;
			box-sizing: border-box;
			margin-bottom: 10rpx;
		}

		.grad {
			flex: 1;
			padding-top: 20rpx;

			ol {
				width: 100%;
				padding: 0;
				display: flex;
				list-style-type: none;
				flex-wrap: wrap;
				justify-content: space-between;

				li {
					display: flex;
					flex-direction: column;
					// justify-content: center;
					align-items: center;
					padding: 10rpx 10rpx 10rpx 10rpx;
					background-color: white;
					width: 28%;
					max-height: 237rpx;
					margin-bottom: 20rpx;
					overflow: hidden;
				}
			}

			.grid-text {
				width: 100%;
				font-size: 26rpx;
				color: $u-type-info;
				word-break: break-all;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				text-align: center;
			}

			._text {
				display: flex;
				overflow: hidden;
				margin-top: 6rpx;
				align-items: center;
				justify-content: center;
				flex: 1;
			}
		}
	}

	.page {
		background-color: #f1f1f1;
		display: flex;
		flex-direction: column;

		.list {
			flex: 1;
			overflow: scroll;
		}

		ol {
			padding: 20rpx;
			list-style-type: none;
			padding: 0;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;

			li {
				width: 30%;
				height: 250rpx;
				background-color: white;
				margin-top: 20rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				overflow: hidden;
			}
		}
	}

	.top {
		height: 130rpx;
		margin-top: 20rpx;
		padding: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		flex-direction: column;
		background: linear-gradient(138deg, rgba(224, 53, 18, 1), rgba(249, 163, 43, 1));
		color: #ffffff;

		.photo {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;

			.avatar {
				display: flex;
				align-items: center;

				text {
					margin-left: 20rpx;
					flex: 1;
					overflow: hidden;
					word-break: break-all;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}

			.ico {
				padding-top: 10rpx;
				box-sizing: border-box;
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
		}
	}
</style>